package com.freesun.shop.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;
import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 微信消息模板
 */
@Data
@Builder  //构造器模式
public class WechatMessage implements Serializable {

    private static final long serialVersionUID = -2281046970106359528L;
    //定义json规则的转化
    @JsonProperty(value = "touser")
    private String toUser;

    @JsonProperty(value = "template_id")
    private String templateId;

    private String url;

    private Map<String,Map<String,String>> data;

    public WechatMessage append(String key,String value, String color) {
        if (this.getData() == null) {
            this.setData(new HashMap<String, Map<String, String>>());
            this.getData().put(key, initMap(value, color));
        }else{
            Map<String, Map<String, String>> msgData = this.getData();
            msgData.put(key,initMap(value,color));
        }
        return this;
    }

    private Map<String, String> initMap(String value, String color) {
      Map<String, String> map = new HashMap<>();
        map.put("value", value);
        map.put("color", color);
        return map;
    }
}
